﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace 第二课堂评审系统.Migrations
{
    /// <inheritdoc />
    public partial class first : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ControllActionTime",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    BeginTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    EndTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ControllActionTime", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Final",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    classRoom = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Final", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Preliminary",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    classRoom = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Preliminary", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "OperationTimes",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Time = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    worker = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProjectId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OperationTimes", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Achievement",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    JudgeId = table.Column<int>(type: "int", nullable: false),
                    PartnarId = table.Column<int>(type: "int", nullable: false),
                    chooseArticle = table.Column<int>(type: "int", nullable: false),
                    developWay = table.Column<int>(type: "int", nullable: false),
                    requireAnalysis = table.Column<int>(type: "int", nullable: false),
                    word = table.Column<int>(type: "int", nullable: false),
                    Function = table.Column<int>(type: "int", nullable: false),
                    technology = table.Column<int>(type: "int", nullable: false),
                    reply = table.Column<int>(type: "int", nullable: false),
                    total = table.Column<int>(type: "int", nullable: false),
                    Session = table.Column<int>(type: "int", nullable: false),
                    PreliminaryId = table.Column<int>(type: "int", nullable: true),
                    finalId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Achievement", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Achievement_T_Final_finalId",
                        column: x => x.finalId,
                        principalTable: "T_Final",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_Achievement_T_Preliminary_PreliminaryId",
                        column: x => x.PreliminaryId,
                        principalTable: "T_Preliminary",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Notice",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Article = table.Column<string>(type: "varchar(25)", maxLength: 25, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    message = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    picture = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    time = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    userId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Notice", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Partnar",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    avatorUrl = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    inviteNum = table.Column<int>(type: "int", nullable: true),
                    guideTeacherId = table.Column<int>(type: "int", nullable: true),
                    counsellor = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    preliminaryId = table.Column<int>(type: "int", nullable: true),
                    finalId = table.Column<int>(type: "int", nullable: true),
                    MyPreliminaryId = table.Column<int>(type: "int", nullable: true),
                    MyFinalId = table.Column<int>(type: "int", nullable: true),
                    searchDirection = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    projectDirection = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    innovateDirection = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Partnar", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Partnar_T_Final_MyFinalId",
                        column: x => x.MyFinalId,
                        principalTable: "T_Final",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_Partnar_T_Final_finalId",
                        column: x => x.finalId,
                        principalTable: "T_Final",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_Partnar_T_Preliminary_MyPreliminaryId",
                        column: x => x.MyPreliminaryId,
                        principalTable: "T_Preliminary",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_Partnar_T_Preliminary_preliminaryId",
                        column: x => x.preliminaryId,
                        principalTable: "T_Preliminary",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Project",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    Name = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Direction = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    isPassed = table.Column<bool>(type: "tinyint(1)", nullable: true),
                    FileUrl = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    projectState = table.Column<int>(type: "int", nullable: true),
                    state = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Project", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Project_T_Partnar_Id",
                        column: x => x.Id,
                        principalTable: "T_Partnar",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_User",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    StuNum = table.Column<int>(type: "int", nullable: false),
                    passWord = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    telPhone = table.Column<string>(type: "varchar(15)", maxLength: 15, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    college = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    track = table.Column<string>(type: "varchar(15)", maxLength: 15, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    avatar = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    address = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    contactAddress = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    email = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    partnarId = table.Column<int>(type: "int", nullable: true),
                    JudgePreId = table.Column<int>(type: "int", nullable: true),
                    JudgeFinId = table.Column<int>(type: "int", nullable: true),
                    isDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_User", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_User_T_Final_JudgeFinId",
                        column: x => x.JudgeFinId,
                        principalTable: "T_Final",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_User_T_Partnar_partnarId",
                        column: x => x.partnarId,
                        principalTable: "T_Partnar",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_T_User_T_Preliminary_JudgePreId",
                        column: x => x.JudgePreId,
                        principalTable: "T_Preliminary",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "T_Role",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UsersId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Role", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Role_T_User_UsersId",
                        column: x => x.UsersId,
                        principalTable: "T_User",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_OperationTimes_ProjectId",
                table: "OperationTimes",
                column: "ProjectId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Achievement_finalId",
                table: "T_Achievement",
                column: "finalId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Achievement_JudgeId",
                table: "T_Achievement",
                column: "JudgeId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Achievement_PartnarId",
                table: "T_Achievement",
                column: "PartnarId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Achievement_PreliminaryId",
                table: "T_Achievement",
                column: "PreliminaryId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Notice_userId",
                table: "T_Notice",
                column: "userId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Partnar_finalId",
                table: "T_Partnar",
                column: "finalId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Partnar_guideTeacherId",
                table: "T_Partnar",
                column: "guideTeacherId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Partnar_MyFinalId",
                table: "T_Partnar",
                column: "MyFinalId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Partnar_MyPreliminaryId",
                table: "T_Partnar",
                column: "MyPreliminaryId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Partnar_preliminaryId",
                table: "T_Partnar",
                column: "preliminaryId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Role_UsersId",
                table: "T_Role",
                column: "UsersId");

            migrationBuilder.CreateIndex(
                name: "IX_T_User_JudgeFinId",
                table: "T_User",
                column: "JudgeFinId");

            migrationBuilder.CreateIndex(
                name: "IX_T_User_JudgePreId",
                table: "T_User",
                column: "JudgePreId");

            migrationBuilder.CreateIndex(
                name: "IX_T_User_partnarId",
                table: "T_User",
                column: "partnarId");

            migrationBuilder.AddForeignKey(
                name: "FK_OperationTimes_T_Project_ProjectId",
                table: "OperationTimes",
                column: "ProjectId",
                principalTable: "T_Project",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Achievement_T_Partnar_PartnarId",
                table: "T_Achievement",
                column: "PartnarId",
                principalTable: "T_Partnar",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_T_Achievement_T_User_JudgeId",
                table: "T_Achievement",
                column: "JudgeId",
                principalTable: "T_User",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_T_Notice_T_User_userId",
                table: "T_Notice",
                column: "userId",
                principalTable: "T_User",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Partnar_T_User_guideTeacherId",
                table: "T_Partnar",
                column: "guideTeacherId",
                principalTable: "T_User",
                principalColumn: "Id");
            //MD5加密算法// 管理员的密码123456

            migrationBuilder.Sql($"INSERT INTO t_user (Name,StuNum, passWord,isDeleted) VALUES ('admin','10001', '{MD5Algorithm.ChangeToMD5("123456")}','0');INSERT INTO t_role (Name,UsersId) VALUES ('A','1')");

        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_T_Partnar_T_Final_MyFinalId",
                table: "T_Partnar");

            migrationBuilder.DropForeignKey(
                name: "FK_T_Partnar_T_Final_finalId",
                table: "T_Partnar");

            migrationBuilder.DropForeignKey(
                name: "FK_T_User_T_Final_JudgeFinId",
                table: "T_User");

            migrationBuilder.DropForeignKey(
                name: "FK_T_User_T_Partnar_partnarId",
                table: "T_User");

            migrationBuilder.DropTable(
                name: "ControllActionTime");

            migrationBuilder.DropTable(
                name: "OperationTimes");

            migrationBuilder.DropTable(
                name: "T_Achievement");

            migrationBuilder.DropTable(
                name: "T_Notice");

            migrationBuilder.DropTable(
                name: "T_Role");

            migrationBuilder.DropTable(
                name: "T_Project");

            migrationBuilder.DropTable(
                name: "T_Final");

            migrationBuilder.DropTable(
                name: "T_Partnar");

            migrationBuilder.DropTable(
                name: "T_User");

            migrationBuilder.DropTable(
                name: "T_Preliminary");
        }
    }
}
